package com.lemon.blog.web.controller;

import com.lemon.blog.web.domain.BlFrontMenu;
import com.lemon.blog.web.service.BlFrontMenuService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 包名称：com.lemon.blog.controller
 * 类名称：BlCommentController
 * 类描述：前台菜单信息controller
 * 创建人：@author huangpeng
 * 创建时间：2022年09月25日 17:08
 */
@Api("前台菜单")
@RestController
@RequestMapping("/menu")
public class BlFrontMenuController extends BaseController {

    @Autowired
    private BlFrontMenuService menuService;

    /**
     * 获取菜单列表
     * @Title: list
     * @Description: 获取菜单列表
     * @param menu
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:43
     */
    @GetMapping("/list")
    public AjaxResult list(BlFrontMenu menu) {
        List<BlFrontMenu> menus = menuService.selectMenuList(menu);
        return AjaxResult.success(menus);
    }

    /**
     * 根据菜单id获取详细信息
     * @Title: getInfo
     * @Description: 根据菜单id获取详细信息
     * @param menuId
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:44
     */
    @GetMapping(value = "/{menuId}")
    public AjaxResult getInfo(@PathVariable Long menuId) {
        return AjaxResult.success(menuService.selectByPrimaryKey(menuId));
    }

    /**
     * 获取菜单下拉树列表
     * @Title: treeSelect
     * @Description: 获取菜单下拉树列表
     * @param menu
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:44
     */
    @GetMapping("/treeSelect")
    public AjaxResult treeSelect(BlFrontMenu  menu) {
        List<BlFrontMenu > menus = menuService.selectMenuList(menu);
        return AjaxResult.success(menuService.buildMenuTreeSelect(menus));
    }

    /**
     * 获取路由信息
     * @Title: getRouters
     * @Description: 获取路由信息
     * @param
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2023/2/26 18:44
     */
    @GetMapping("getRouters")
    public AjaxResult getRouters() {
        List<BlFrontMenu > menus = menuService.selectMenuTree();
        return AjaxResult.success(menuService.buildMenus(menus));
    }
}